package com.foreveross.taskservice.application.impl.convert;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.foreveross.taskservice.common.TaskTypeConst;
import com.foreveross.taskservice.common.model.airfreight.AirFreightTaskModel;
import com.foreveross.taskservice.core.domain.statitics.entity.EngineStatisticsEntity;
import com.foreveross.taskservice.core.domain.task.TaskQueueRecordEntity;
import com.google.common.collect.Lists;

public class AirFreightTaskConvert {
	/**
	 * 将任务记录实体转化为任务模型
	 * @param entity
	 * @return
	 */
	public static AirFreightTaskModel convertEntity2Model(TaskQueueRecordEntity entity){
		AirFreightTaskModel model=new AirFreightTaskModel();
		BeanUtils.copyProperties(entity, model);
		model.setTaskType(TaskTypeConst.AIRFREIGHT_TASKTYPE);//一个很重要的任务类型
		return model;
	}
	
	public static List<AirFreightTaskModel> convertEntity2Model(Collection<TaskQueueRecordEntity> entitys){
		List<AirFreightTaskModel> result=Lists.newArrayList();
		for(TaskQueueRecordEntity e:entitys){
			result.add(convertEntity2Model(e));
		}
		return result;
	}
	
	/**
	 * 将任务模型转化为任务记录实体
	 * @param model
	 * @return
	 */
	public static TaskQueueRecordEntity convertModel2Entity(AirFreightTaskModel model){
		TaskQueueRecordEntity entity=new TaskQueueRecordEntity();
		BeanUtils.copyProperties(model, entity);
		if(model.getChannel()!=null){
			entity.setGrabChannelId(model.getChannel().getId());
			entity.setGrabChannel(model.getChannel().getName());
		}
		return entity;
	}
	 
	public static  List<TaskQueueRecordEntity> convertModel2Entity(Collection<AirFreightTaskModel> models){
		List<TaskQueueRecordEntity> entitys=Lists.newArrayList();
		for(AirFreightTaskModel model:models){
			entitys.add(convertModel2Entity(model));
		}
		return entitys;
	}
	
	/**
	 * 将任务模型转化为统计实体
	 * @param model
	 * @return EngineStatisticsEntity
	 */
	public static EngineStatisticsEntity EngineStatisticsEntity(AirFreightTaskModel model){
		EngineStatisticsEntity entity=new EngineStatisticsEntity();
		BeanUtils.copyProperties(model, entity);
		if(model.getChannel()!=null){
			entity.setChannelId(model.getChannel().getId());
			entity.setChannelName(model.getChannel().getName());
		}
		return entity;
	}
	
	public static List<EngineStatisticsEntity> EngineStatisticsEntity(Collection<AirFreightTaskModel> models){
		List<EngineStatisticsEntity> listEntity=Lists.newArrayList();
		for(AirFreightTaskModel model:models){
			listEntity.add(EngineStatisticsEntity(model));
		}
		return listEntity;
	}
	
}
